/*
 * Orden.java
 *
 * Created on 26 de octubre de 2007, 07:18 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package data;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * Entity class Orden
 * 
 * @author Fanny Paola Vadillo Herrera
 * @author Luis Manuel Pineda Llano
 */
@Entity
@Table(name = "orden")
@NamedQueries( {
        @NamedQuery(name = "Orden.findById", query = "SELECT o FROM Orden o WHERE o.id = :id"),
        @NamedQuery(name = "Orden.findByCliente", query = "SELECT o FROM Orden o WHERE o.cliente = :cliente"),
        @NamedQuery(name = "Orden.findByFecha", query = "SELECT o FROM Orden o WHERE o.fecha = :fecha"),
        @NamedQuery(name = "Orden.findByTotal", query = "SELECT o FROM Orden o WHERE o.total = :total"),
        @NamedQuery(name = "Orden.findByHoraRecibido", query = "SELECT o FROM Orden o WHERE o.horaRecibido = :horaRecibido"),
        @NamedQuery(name = "Orden.findByPagado", query = "SELECT o FROM Orden o WHERE o.pagado = :pagado"),
        @NamedQuery(name = "Orden.findForCuenta", query = "SELECT o FROM Orden o WHERE o.idMesa = :mesa AND o.pagado = 0 AND o.fecha = :fecha ORDER BY o.cliente")
    })
public class Orden implements Serializable {

    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name = "id", nullable = false)
    private Integer id;

    @Column(name = "cliente", nullable = false)
    private int cliente;

    @Column(name = "fecha", nullable = false)
    @Temporal(TemporalType.DATE)
    private Date fecha;

    @Column(name = "total", nullable = false)
    private double total;

    @Column(name = "horaRecibido")
    @Temporal(TemporalType.TIME)
    private Date horaRecibido;

    @Column(name = "pagado")
    private Boolean pagado;

    @JoinColumn(name = "idMesa", referencedColumnName = "numero")
    @ManyToOne
    private Mesa idMesa;

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "orden")
    private Collection<OrdenPlatillo> ordenPlatilloCollection;
    
    /** Creates a new instance of Orden */
    public Orden() {
    }

    /**
     * Creates a new instance of Orden with the specified values.
     * @param id the id of the Orden
     */
    public Orden(Integer id) {
        this.id = id;
    }

    /**
     * Creates a new instance of Orden with the specified values.
     * @param id the id of the Orden
     * @param cliente the cliente of the Orden
     * @param fecha the fecha of the Orden
     * @param total the total of the Orden
     */
    public Orden(Integer id, int cliente, Date fecha, double total) {
        this.id = id;
        this.cliente = cliente;
        this.fecha = fecha;
        this.total = total;
    }

    /**
     * Gets the id of this Orden.
     * @return the id
     */
    public Integer getId() {
        return this.id;
    }

    /**
     * Sets the id of this Orden to the specified value.
     * @param id the new id
     */
    public void setId(Integer id) {
        this.id = id;
    }

    /**
     * Gets the cliente of this Orden.
     * @return the cliente
     */
    public int getCliente() {
        return this.cliente;
    }

    /**
     * Sets the cliente of this Orden to the specified value.
     * @param cliente the new cliente
     */
    public void setCliente(int cliente) {
        this.cliente = cliente;
    }

    /**
     * Gets the fecha of this Orden.
     * @return the fecha
     */
    public Date getFecha() {
        return this.fecha;
    }

    /**
     * Sets the fecha of this Orden to the specified value.
     * @param fecha the new fecha
     */
    public void setFecha(Date fecha) {
        this.fecha = fecha;
    }

    /**
     * Gets the total of this Orden.
     * @return the total
     */
    public double getTotal() {
        return this.total;
    }

    /**
     * Sets the total of this Orden to the specified value.
     * @param total the new total
     */
    public void setTotal(double total) {
        this.total = total;
    }

    /**
     * Gets the horaRecibido of this Orden.
     * @return the horaRecibido
     */
    public Date getHoraRecibido() {
        return this.horaRecibido;
    }

    /**
     * Sets the horaRecibido of this Orden to the specified value.
     * @param horaRecibido the new horaRecibido
     */
    public void setHoraRecibido(Date horaRecibido) {
        this.horaRecibido = horaRecibido;
    }

    /**
     * Gets the pagado of this Orden.
     * @return the pagado
     */
    public Boolean getPagado() {
        return this.pagado;
    }

    /**
     * Sets the pagado of this Orden to the specified value.
     * @param pagado the new pagado
     */
    public void setPagado(Boolean pagado) {
        this.pagado = pagado;
    }

    /**
     * Gets the idMesa of this Orden.
     * @return the idMesa
     */
    public Mesa getIdMesa() {
        return this.idMesa;
    }

    /**
     * Sets the idMesa of this Orden to the specified value.
     * @param idMesa the new idMesa
     */
    public void setIdMesa(Mesa idMesa) {
        this.idMesa = idMesa;
    }

    /**
     * Gets the ordenPlatilloCollection of this Orden.
     * @return the ordenPlatilloCollection
     */
    public Collection<OrdenPlatillo> getOrdenPlatilloCollection() {
        return this.ordenPlatilloCollection;
    }

    /**
     * Sets the ordenPlatilloCollection of this Orden to the specified value.
     * @param ordenPlatilloCollection the new ordenPlatilloCollection
     */
    public void setOrdenPlatilloCollection(Collection<OrdenPlatillo> ordenPlatilloCollection) {
        this.ordenPlatilloCollection = ordenPlatilloCollection;
    }

    /**
     * Returns a hash code value for the object.  This implementation computes 
     * a hash code value based on the id fields in this object.
     * @return a hash code value for this object.
     */
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (this.id != null ? this.id.hashCode() : 0);
        return hash;
    }

    /**
     * Determines whether another object is equal to this Orden.  The result is 
     * <code>true</code> if and only if the argument is not null and is a Orden object that 
     * has the same id field values as this object.
     * @param object the reference object with which to compare
     * @return <code>true</code> if this object is the same as the argument;
     * <code>false</code> otherwise.
     */
    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Orden)) {
            return false;
        }
        Orden other = (Orden)object;
        if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) return false;
        return true;
    }

    /**
     * Returns a string representation of the object.  This implementation constructs 
     * that representation based on the id fields.
     * @return a string representation of the object.
     */
    @Override
    public String toString() {        
        String hora = horaRecibido.toString();
        return hora.substring(11, 19);
    }
}